package cn.stylefeng.guns.modular.tool.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.tool.entity.ToolExpressReconciliationYqbInstall;
import cn.stylefeng.guns.modular.tool.mapper.ToolExpressReconciliationYqbInstallMapper;
import cn.stylefeng.guns.modular.tool.model.params.ToolExpressReconciliationYqbInstallParam;
import cn.stylefeng.guns.modular.tool.model.result.ToolExpressReconciliationYqbInstallResult;
import  cn.stylefeng.guns.modular.tool.service.ToolExpressReconciliationYqbInstallService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 一起吧报价设置 服务实现类
 * </p>
 *
 * @author zhucx
 * @since 2023-05-29
 */
@Service
public class ToolExpressReconciliationYqbInstallServiceImpl extends ServiceImpl<ToolExpressReconciliationYqbInstallMapper, ToolExpressReconciliationYqbInstall> implements ToolExpressReconciliationYqbInstallService {

    @Override
    public void add(ToolExpressReconciliationYqbInstallParam param){
        ToolExpressReconciliationYqbInstall entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ToolExpressReconciliationYqbInstallParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ToolExpressReconciliationYqbInstallParam param){
        ToolExpressReconciliationYqbInstall oldEntity = getOldEntity(param);
        ToolExpressReconciliationYqbInstall newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ToolExpressReconciliationYqbInstallResult findBySpec(ToolExpressReconciliationYqbInstallParam param){
        return null;
    }

    @Override
    public List<ToolExpressReconciliationYqbInstallResult> findListBySpec(ToolExpressReconciliationYqbInstallParam param,Long operateId){
        return this.baseMapper.findListBySpec(param, operateId);
    }

    @Override
    public LayuiPageInfo findPageBySpec(ToolExpressReconciliationYqbInstallParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition,operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ToolExpressReconciliationYqbInstallParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ToolExpressReconciliationYqbInstall getOldEntity(ToolExpressReconciliationYqbInstallParam param) {
        return this.getById(getKey(param));
    }

    private ToolExpressReconciliationYqbInstall getEntity(ToolExpressReconciliationYqbInstallParam param) {
        ToolExpressReconciliationYqbInstall entity = new ToolExpressReconciliationYqbInstall();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
